package com.kgc.kmall.kmallcloudmanagerservice.service;

import com.kgc.kmall.bean.*;
import com.kgc.kmall.kmallcloudmanagerservice.mapper.PmsBaseSaleAttrMapper;
import com.kgc.kmall.kmallcloudmanagerservice.mapper.PmsProductInfoMapper;
import com.kgc.kmall.kmallcloudmanagerservice.mapper.PmsProductSaleAttrMapper;
import com.kgc.kmall.kmallcloudmanagerservice.mapper.PmsProductSaleAttrValueMapper;
import com.kgc.kmall.service.SpuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class SpuServiceImpl implements SpuService{
    @Resource
    PmsProductInfoMapper pmsProductInfoMapper;
    @Resource
    PmsProductSaleAttrMapper pmsProductSaleAttrMapper;
    @Resource
    PmsBaseSaleAttrMapper pmsBaseSaleAttrMapper;
    @Resource
    PmsProductSaleAttrValueMapper pmsProductSaleAttrValueMapper;
    @Override
    public List<PmsProductInfo> spuList(Long catalog3Id) {
        PmsProductInfoExample example=new PmsProductInfoExample();
        example.createCriteria().andCatalog3IdEqualTo(catalog3Id);
        List<PmsProductInfo> pmsProductInfos = pmsProductInfoMapper.selectByExample(example);
        return pmsProductInfos;
    }

    @Override
    public List<PmsProductSaleAttr> spuSaleAttrList(Long spuId) {
        PmsProductSaleAttrExample example=new PmsProductSaleAttrExample();
        example.createCriteria().andProductIdEqualTo(spuId);
        List<PmsProductSaleAttr> saleAttrList = pmsProductSaleAttrMapper.selectByExample(example);
        for (PmsProductSaleAttr pmsProductSaleAttr : saleAttrList) {
            PmsProductSaleAttrValueExample example1=new PmsProductSaleAttrValueExample();
            PmsProductSaleAttrValueExample.Criteria criterias=example1.createCriteria();
            criterias.andProductIdEqualTo(spuId);
            criterias.andSaleAttrIdEqualTo(pmsProductSaleAttr.getSaleAttrId());
            List<PmsProductSaleAttrValue> pmsProductSaleAttrValues = pmsProductSaleAttrValueMapper.selectByExample(example1);
            pmsProductSaleAttr.setSpuSaleAttrValueList(pmsProductSaleAttrValues);
        }
        return saleAttrList;
    }


}
